<template>
  <!-- <div> -->
  <el-dialog title="业务机构" :visible.sync="isShow" width="890px" @open="openCreate" :close-on-click-modal="false" center>
    <div v-loading="loading">
      <el-card>
        <div>
          <el-form :model="form" size="mini" label-position="left" ref="form1">
            <el-row :gutter="10">
              <el-col :sm="12">
                <el-form-item label="用户编号" prop="ID">
                  <el-input v-model="form.ID" placeholder="" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
              <el-col :sm="12">
                <el-form-item label="用户名称" prop="name">
                  <el-input v-model="form.name" placeholder="" :disabled="true"></el-input>
                </el-form-item>
              </el-col>
            </el-row>
          </el-form>
        </div>
      </el-card>
      <el-card style="margin:10px 0 0 0;">
        <div>
          <el-transfer filterable :titles="['可分配机构', '已分配机构']" :filter-method="filterMethod" filter-placeholder=""
            v-model="form.branchId" :data="transList">
          </el-transfer>
        </div>
      </el-card>
    </div>


    <span slot="footer" class="dialog-footer">
      <el-button size="mini" @click="isShow = false">取 消</el-button>
      <el-button size="mini" type="primary" @click="queryFunc">确 定</el-button>
    </span>
  </el-dialog>
  <!-- </div> -->
</template>
<script>
  import allBusBranchQry from "@/message/userManage/user/busBranch/allbusbranch-query";
  import busBranchQry from "@/message/userManage/user/busBranch/busbranch-query";
  import busBranchSub from "@/message/userManage/user/busBranch/busbranch-submit";
  import request from "@/common/utils/request";
  import toolBox from "@/common/utils/toolBox";



  export default {
    props: {
      option: Object
    },
    data() {
      return {
        brnoList: [],
        transList: [],
        form: {
          ID: "",
          name: "",
          branchId: []
        },
        date: "",
        time: "",
        loading: false,
        tableData: [],
        newUserDate: {
          userNum: "",
          userName: ""
        },
        dialogList: {}
      };
    },
    methods: {
      filterMethod(query, item) {
        return item.label.indexOf(query) > -1;
      },
      initList() {
        this.loading = true;
        //初始化支行列表
        let resBody = new allBusBranchQry();
        request(resBody)
          .then(response => {
            this.transList = [];
            let results = response.RspInfo.Result ||[];
            results.forEach((item, index) => {
              this.transList.push({
                label: item.BranchNum + "-" + item.BranchName,
                key: item.BranchNum,
                disabled : false
              });
            });
          })
          .catch(error => {
            this.loading = false;
            console.error("错误信息", error);
          });
        //也有业务机构加载
        let resBody1 = new busBranchQry();
        resBody1.data.UserNum = this.form.ID;
        request(resBody1)
          .then(response => {
            this.form.branchId = [];
            let results1 =response.RspInfo.Result || [];
            results1.forEach((item, index) => {
              this.form.branchId.push(
                item.BranchNum
              );
              this.loading = false;
            });
          })
          .catch(error => {
            this.loading = false;
            console.error("错误信息", error);
          });
      },
      openCreate() {
        this.form.ID = this.option.currentRow.UserNum;
        this.form.name = this.option.currentRow.UserName;
        this.initList();
      },
      queryFunc() {
        this.loading = true;
        let _this =this;
        let resBody = new busBranchSub();
        resBody.data.UserNum = this.form.ID;
        _this.brnoList= [];
        for(let i=0;i<this.form.branchId.length;i++){
            _this.brnoList.push({
            "UserNum": this.form.ID,
            "AssoCate": "1",
            "AssoInfo": this.form.branchId[i],
            "MainUser": "",
            "MainBranch": "",
            "MainDate": "",
            "MainTime": ""
          });
        }
        resBody.data.UserList=_this.brnoList;
        request(resBody)
          .then(response => {
              this.$message({
                type: "success",
                message: "修改成功!"
              });
              this.loading = false;
              this.isShow = false;
          })
          .catch(error => {
            this.loading = false;
            console.error("错误信息", error);
          });
        this.loading = false;
      },
      // systemEmit() {
      //   this.$emit("systemEmit");
      // },
      closeSystem() {
        // this.$emit("refreshTable")
      }
    },
    computed: {
      isShow: {
        get() {
          return this.option.isShow;
        },
        set(value) {
          this.option.isShow = value;
        }
      }
    },
    mounted() {
    }
  };

</script>
<style lang="scss" scoped>
  .clearfix:after {
    clear: both;
  }

  .el-card {
    overflow: inherit;
  }

  /deep/ .el-transfer-panel {
    min-width: 334px;
  }

  .el-transfer-panel__list{
    overflow: visible
  }

</style>
